home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / sound.267 < prev    next >
Text File  |  1992-02-06  |  3KB  |  46 lines

  1. sound loop repeat chain didPlay duration SNDWait  
  2.  
  3. Q:  How can I determine a Sound's duration?
  4.  
  5. A:  Send the Sound the sampleCount and samplingRate methods (if necessary) and divide the former number by the latter.
  6.  
  7. Q:  How can I get Sounds to repeat one after the other, or the same one multiple times? 
  8.  
  9. A:  There are several approaches; however, none of them is guaranteed to work in all possible situations.
  10.  
  11. (1) You can compute the duration of each sound just before you play it (following the approach in the answer to the first question).  Set up a timed entry (see documentation on DPSAddTimedEntry) that will occur at a time equal to the sound's duration plus any desired delay between playings.  When you get this timed entry, you tell the next Sound to play, and so forth.  
  12.  
  13. (2)  If you don't require an Application event loop, you can reliably chain sounds together using the Sound library C functions.  See the example file /NextDeveloper/Examples/Sound/chaintest.c, and the README file in the same directory.  You are advised to use the SNDNotificationFun approach, as in this example, and to avoid the SNDWait() function.
  14.  
  15. (3) If you require an Application with an event loop (the normal case), you might have success using the Sound Kit delegation method didPlay:.  Create an object that will be the Sound's delegate, or use an existing object.  Give it these methods:
  16.     
  17.      int sndCtr;
  18.  
  19.     - init {
  20.            [mySound setDelegate:self];    /* mySound is the Sound to be looped */
  21.            sndCtr = 1;
  22.     }
  23.       
  24.     - playIt {
  25.          [mySound play];
  26.     }
  27.       
  28.     - didPlay:sender {
  29.             if (sndCtr++ < NUMTIMES)
  30.                [self playIt];                /* play it NUMTIMES in a row.  Alternately, use some other
  31.                                 terminating condition, or trigger other Sounds here */
  32.     } 
  33.  
  34. This approach sometimes causes problems in the playback, however, particularly if the user will be interrupting the playing with an event such as a mouse-down.   You'll have to try it for your specific case and see whether it works.
  35.  
  36. (4) If none of these approaches is suitable, the workaround is to create a new Sound composed of multiple copies of the desired sound(s), using the SoundKit's copy/paste functionality.  You can do this splicing programmatically with the insertSamples:at: method, or manually by using the SoundEditor example.
  37.  
  38. (5) As a final option, you can combine the chaintest strategy with the Sound Kit example above.  Override Sound's "play" method and directly enqueue the soundstruct with SNDStartPlaying, giving it your own special SNDNotificationFun to do the chaining as in chaintest.  The drawback of this approach is that you cannot safely send the delegate a soundDidPlay: message when the repeat count runs out.
  39.  
  40. QA267
  41.  
  42. Valid for 1.0
  43. Valid for 2.0
  44.  
  45.  
  46.